home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume4 / bridge / part01 next >
Encoding:
Internet Message Format  |  1988-04-29  |  56.8 KB

  1. Path: uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games
  2. From: games@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v04i019:  bridge - multiplayer networked bridge game, Part01/02
  5. Message-ID: <2581@tekred.TEK.COM>
  6. Date: 31 May 88 16:14:00 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2101
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted by: Jiang-Hsing Chu <jchu@mimsy.umd.edu>
  12. Comp.sources.games: Volume 4, Issue 19
  13. Archive-name: bridge/Part01
  14.  
  15.     [This is a program that allows four persons to play bridge at
  16.      different places, different computers, via the computer
  17.      communication.  Now that you've practiced your bidding with
  18.      v4i018, you can start playing.  -br]
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 1 (of 2)."
  27. # Contents:  README MANIFEST bridge.README bridge.c ctl_transact.c
  28. #   init_disp.c invite.c look_up.c master_io.c master_talk.c msgs.c
  29. #   slave_io.c
  30. # Wrapped by billr@saab on Tue May 31 09:13:29 1988
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f README -a "${1}" != "-c" ; then 
  33.   echo shar: Will not over-write existing file \"README\"
  34. else
  35. echo shar: Extracting \"README\" \(860 characters\)
  36. sed "s/^X//" >README <<'END_OF_README'
  37. XThis program provides communication between different machines so that people
  38. Xcan play bridge even they are on different machine.  It is written by
  39. XShyan-Ming Yuan and Jiang-Hsing Chu at University of Maryland, College Park.
  40. XIt was tested on Vaxes and Sun 3/50 running BSD 4.2 and BSD 4.3.
  41. XSince we don't have the previlege to create a 'bridge daemon' as a normal user,
  42. Xwe decided to use 'talk daemon' instead.  The underlying communication program
  43. Xis modified from the 'talk' program.  You will have confusion in trying to
  44. Xconnect to the others, this is also explained in bridge.README.
  45. X
  46. XYou are free to use, copy, and modify these programs.  You receive the program
  47. Xas it is.  No warranty.  No major update is expected.  But bug report is
  48. Xwelcome.  If you have a major modification, please send me a new copy.
  49. XThanks.  Jiang-Hsing Chu.    e-mail: jchu@mimsy
  50. END_OF_README
  51. if test 860 -ne `wc -c <README`; then
  52.     echo shar: \"README\" unpacked with wrong size!
  53. fi
  54. # end of overwriting check
  55. fi
  56. if test -f MANIFEST -a "${1}" != "-c" ; then 
  57.   echo shar: Will not over-write existing file \"MANIFEST\"
  58. else
  59. echo shar: Extracting \"MANIFEST\" \(744 characters\)
  60. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  61. X   File Name        Archive #    Description
  62. X-----------------------------------------------------------
  63. X MANIFEST                  1    This shipping list
  64. X Makefile                  2    
  65. X README                    1    
  66. X bridge.README             1    
  67. X bridge.c                  1    
  68. X ctl.c                     2    
  69. X ctl.h                     2    
  70. X ctl_transact.c            1    
  71. X get_addrs.c               2    
  72. X get_names.c               2    
  73. X init_disp.c               1    
  74. X invite.c                  1    
  75. X invitebridge.README       2    
  76. X look_up.c                 1    
  77. X master_io.c               1    
  78. X master_talk.c             1    
  79. X msgs.c                    1    
  80. X slave_io.c                1    
  81. X slave_talk.c              2    
  82. X talk.h                    2    
  83. X talk_ctl.h                2    
  84. END_OF_MANIFEST
  85. if test 744 -ne `wc -c <MANIFEST`; then
  86.     echo shar: \"MANIFEST\" unpacked with wrong size!
  87. fi
  88. # end of overwriting check
  89. fi
  90. if test -f bridge.README -a "${1}" != "-c" ; then 
  91.   echo shar: Will not over-write existing file \"bridge.README\"
  92. else
  93. echo shar: Extracting \"bridge.README\" \(7255 characters\)
  94. sed "s/^X//" >bridge.README <<'END_OF_bridge.README'
  95. XBridge is the program stored in the local site so that the player can 
  96. Xcommunicate with other remote players.  To be able to use this program,
  97. Xyou must have a terminal supporting "curses".  When you are invited to play
  98. Xthe game, a message will be shown on your screen indicating someone
  99. Xwants to talk to you as the talk program does and requests you to type
  100. X'talk xxx@yyy.zzz.edu'.  At this moment, you should type 'bridge
  101. Xxxx@yyy.zzz.edu' to make the connection.  It's obviously confusing because 
  102. Xyou don't know the message is coming form some one who wants to talk to 
  103. Xyou or form some one who wants to play bridge with you.  Unfortunately,
  104. Xthis is what we have so far, we may be able to improve it later.
  105. XThe confusion can be avoided by presetting the time for playing bridge
  106. Xvia talk or mail in advance.  You can assume that you are invited to 
  107. Xplay bridge when talk Daemon shows the message around the preset time.
  108. X
  109. XSince we assume that all the users of 'bridge' are experienced computer
  110. Xusers and bridge players, there will not be any HELP information other
  111. Xthan those shown on the screen.  Please read the followings carefully
  112. Xbefore you start to use the program.
  113. X
  114. X(1)General Guide:
  115. X   1. Always end your input with a carriage return.
  116. X   2. Input only when you are prompted to avoid mistakes.
  117. X   3. Some abbreviations are used:
  118. X      N: No Trump, S: Spade, H: Heart, D: Diamond, C: Club,
  119. X      X: Double, XX: Redouble, P: Pass, T: 10.
  120. X
  121. X(2)Bidding:
  122. X   You will be prompted when it is your turn to bid.  You will be prompted
  123. X   again if your bid is illegal.  To make a bid, type the rank(between 1 and 7)
  124. X   followed by the suit(N,S,H,D,C); or type P, X, and XX for Pass, Double, 
  125. X   and Redouble respectively.  Remember to end it with a carriage return.
  126. X   Please note that a single carriage return means PASS.
  127. X   The followings are legal INPUTs (not necessary legal bids):
  128. X     1H, 2N, 4C, X, XX, P,...
  129. X   The followings are not legal inputs:
  130. X     5, S, 0D, 8C, ....
  131. X   All the inputs are checked for the validity according to the rules of
  132. X   bridge game.  You are encouraged to report any illegal bid which is
  133. X   accepted by the program.
  134. X
  135. X(3)Playing:
  136. X   You will be prompted when it is your turn to play.  You will be prompted
  137. X   again if your play is illegal.  To make a play, type the suit(S,H,D,C)
  138. X   followed by the face value(2,3,...,9,T,J,Q,K,A) and end it with a carriage
  139. X   return.  There are three special features for playing:
  140. X   1. Following:
  141. X      When you are not the first person to lead a card, you can simply input
  142. X      the face value(2,3,...,T,J,Q,K,A) which means you are following the
  143. X      same suit.  For example, if your right hand side opponent leads S3, you
  144. X      can type J instead of SJ when you want to play SJ.
  145. X   2. Don't Care:
  146. X      When you have only one choice or you don't care which card is to be 
  147. X      played, you can simply type a carriage return.  In such case, the porgram
  148. X      will automatically play the card which is a legal play and has the lowest
  149. X      rank.  The cards are ranked as: SA>SK>...>S2>HA>...>C2.  To avoid the
  150. X      disaster caused by typing mistake, this function is disabled when you
  151. X      are in the position to lead a card except the last round.
  152. X   3. Finish Quickly (claim):
  153. X      The declarer, in his turn or dummy's turn to play, can claim the number
  154. X      of tricks he can win to save time.  To make the claim, the declarer
  155. X      has to type in Fn, where n is a number between 0 and 13 which means
  156. X      declarer is willing to finish the game with n MORE tricks.  A single
  157. X      "F" without any number followed means all the tricks left.  This claim
  158. X      is subject to the approval of the opponents.  All the cards will be
  159. X      shown on the opponents' screen to make their decision easier.  If the
  160. X      opponents don't agree to finish the game, the play is resume after
  161. X      all extra cards are erased from the opponents' screen.
  162. X
  163. X(4)Scoring
  164. X   The scoring system of our birdge program is rubber.  To win the rubber
  165. X   bonus, basically, you have to win two games before your opponents do.  
  166. X   Thus, you might need a different strategy in playing rubbers.  For your
  167. X   convenience, the scoring rule is also enclosed. Due to the limited space
  168. X   on the screen, please note the following notation:
  169. X
  170. X         N-S  E-W
  171. X      TRICK  ...  ...  <-- number of tricks won by each side so far
  172. X      SCORE  ...  ...  <-- score below the line (see the attached scoring rule)
  173. X                            which doesn't exceed 100 points.
  174. X      TOTAL  ...  ...  <-- total score (including the score in SCORE entry) won
  175. X                          by each side so far
  176. X
  177. XIt is also important to know whether you and/or your opponents have won a game
  178. Xalready.  To gain this information, you have to look at the upper left corner
  179. Xon the screen, i.e. the VUL field.  It can be interpreted as:
  180. X
  181. X            VUL.
  182. X
  183. X            NONE    <-- neither side has won a game
  184. X            N-S     <-- N-S has won a game, but E-W hasn't
  185. X            E-W     <-- E-W has won a game, but N-S hasn't
  186. X            BOTH    <-- both N-S and E-W have won a game
  187. X
  188. X(5) Conversation:
  189. X    All your inputs are sent to the bridge program when you are in input
  190. X    mode.  However, if you are in conversation mode, all your inputs will
  191. X    be sent to the screens of all other players (same as talk does, but it
  192. X    is a multiway talk).  The ESC key is used to switch back and forth
  193. X    between input mode and conversation mode.  You will be put in the input
  194. X    mode at the beginning of the game.
  195. X
  196. X(6)Ending:
  197. X   There is not a graceful way to end this program.  It will run forever
  198. X   unless you type a ctrl-C. 
  199. X
  200. X==============================================================================
  201. XSCORING TABLE
  202. X
  203. XTrick Score (below the line)
  204. X
  205. XSpades of Hearts    30 per trick    |  If doubled:
  206. XDiamonds or Clubs    20 per trick    |    multiply by 2
  207. XNotrump        40 for first trick    |  If redoubled:
  208. X    30 for each additional trick    |    multiply by 4
  209. X
  210. XGame - 100 points or more below the line
  211. X
  212. XBonuses (above the line)
  213. X
  214. XRubber bonus:    500 if you win two games out of three
  215. X        700 if you win the only two games
  216. X
  217. X            Not Vulnerable        Vulnerable
  218. XSlam Bonus:  Small Slam         500            750
  219. X         Grand Slam        1000           1500
  220. X
  221. X/* NOT IMPLEMENTED
  222. XHonors:  4 trump honors in one hand        100
  223. X     5 trump honors in one hand        150
  224. X     4 aces in one hand at notrump        150
  225. X*/
  226. X
  227. XMaking Doubled (or redoubled) Contract:     50 points
  228. X
  229. X            Not Vulnerable        Vulnerable
  230. XOvertricks:  Undoubled      trick value        trick value
  231. X         Doubled      100 per trick        200 per trick
  232. X         Redoubled      200 per trick         400 per trick
  233. X
  234. XPenalties (above the line)
  235. X
  236. X            Undoubled        Doubled
  237. X        Not Vul.    Vul.      Not Vul.    Vul.
  238. XDown 1           50        100        100        200
  239. XDown 2          100        200        300        500
  240. XDown 3          150        300        500        800
  241. XDown 4          200        400        700           1100
  242. XDown 5          250        500        900           1400
  243. XDown 6          300        600       1100           1700
  244. XDown 7          350        700       1300        2100
  245. XDown 8          400        800       1500           2500
  246. X  .                .             .           .           .
  247. X  .                .             .           .           .
  248. X  .                .             .           .           .
  249. X
  250. XIf redoubled: multiply the doubled penalty by two.
  251. X
  252. X=============================================================================
  253. X
  254. END_OF_bridge.README
  255. if test 7255 -ne `wc -c <bridge.README`; then
  256.     echo shar: \"bridge.README\" unpacked with wrong size!
  257. fi
  258. # end of overwriting check
  259. fi
  260. if test -f bridge.c -a "${1}" != "-c" ; then 
  261.   echo shar: Will not over-write existing file \"bridge.c\"
  262. else
  263. echo shar: Extracting \"bridge.c\" \(14041 characters\)
  264. sed "s/^X//" >bridge.c <<'END_OF_bridge.c'
  265. X#include <stdio.h>
  266. X
  267. X#define EQ ==
  268. X#define NEQ !=
  269. X#define NOT !
  270. X#define AND &&
  271. X#define OR ||
  272. X#define TRUE 1
  273. X#define FALSE 0
  274. X
  275. X#define SIDE(i) ((i)%2)
  276. X#define NEXT(i) ((i+1)%4)
  277. X#define PARTNER(i) ((i+2)%4)
  278. X#define IC(i) (i+'0')
  279. X#define ALLp p=0;p<=3;++p
  280. X
  281. XFILE *f1;
  282. Xchar scr[16][80];
  283. Xint  r[4]={1,6,11,6},c[4]={18,32,18,4};
  284. Xint hand= -1,decl,dummy,trump,dbl,ld,ldd,win[2],HBR,HBS,HBB,rs,ts[2]={0,0};
  285. Xint vt[2]={0,0},part[2]={0,0};
  286. Xint eofg,eofp,eofr=0;
  287. Xint card[52],C[4][52],NS[4][4],LS[4];
  288. Xint TV[5]={20,20,30,30,30};
  289. Xint VUL[2][16]={0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,
  290. X                0,0,1,1,0,1,1,0,1,1,0,0,1,0,0,1};
  291. Xchar CBR,CBS,CPR,CPS;
  292. Xextern char player[4][20];
  293. Xchar str[80],inp[80],num[6];
  294. Xchar FV[13]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
  295. Xchar SV[5]={'C','D','H','S','N'};
  296. Xchar P[4]={'N','E','S','W'};
  297. Xextern long seed;
  298. X
  299. Xinit()
  300. X{  int p,t;
  301. X
  302. X   f1=fopen("bridge.log","w");
  303. X   for(ALLp){player[p][0]=P[p];player[p][1]=':';}
  304. X   for(ALLp){
  305. X      str[1]='\0';
  306. X      str[0]=P[PARTNER(p)];
  307. X      rput(p,13,4,29,str);
  308. X      str[0]=P[t=NEXT(p)];
  309. X      rput(p,13,8,20,str);
  310. X      str[0]=P[PARTNER(t)];
  311. X      rput(p,13,8,38,str);
  312. X      str[0]=P[p];
  313. X      rput(p,13,12,29,str);
  314. X      rput(p,13,17,5,player[(p+2)%4]);
  315. X      rput(p,13,17,25,player[(p+1)%4]);
  316. X      rput(p,13,17,45,player[p]);
  317. X      rput(p,13,17,65,player[(p+3)%4]);
  318. X   }
  319. X   srandom(seed);
  320. X}
  321. Xrinit()
  322. X{  int tvt,p,i,j;
  323. X   char *d;
  324. X
  325. X   for(i=0;i<16;i++){
  326. X      d=(char *)&scr[i][0];
  327. X      for(j=0;j<80;++j) *d++ =' ';
  328. X   }
  329. X   sput("Hand:",0,0);sput("Vul.:",1,0);
  330. X   sput("Bid",0,51);sput("=N==E==S==W==",1,46);
  331. X   sput("Play",0,66);sput("=N===E===S===W===",1,60);
  332. X   sput("--------------",5,17);
  333. X   sput("|     N      |",6,17);
  334. X   sput("|W          E|",7,17);
  335. X   sput("|            |",8,17);
  336. X   sput("|     S      |",9,17);
  337. X   sput("--------------",10,17);
  338. X   sput("Result:",15,47);
  339. X   itos((++hand)+1);
  340. X   sput(num+3,0,6);
  341. X   for(ALLp)rput(p,8,0,0,num+3);
  342. X
  343. X/* for duplicate bridge
  344. X   sput("Score:",15,62);
  345. X   tvt=VUL[0][hand%16]*2+VUL[1][hand%16];
  346. X*/
  347. X/* for rubber */
  348. X   tvt=vt[0]*2+vt[1];
  349. X   for(ALLp){ clearw(p,11); clearw(p,10);}
  350. X   str[1]='\0';
  351. X   switch(tvt){
  352. X      case 0: for(ALLp)rput(p,8,1,0,"NONE");sput("NONE",1,6);break;
  353. X      case 1: for(ALLp){
  354. X                 rput(p,8,1,0,"E-W ");
  355. X                 str[0]=45+SIDE(p)*79;
  356. X                 rput(p,10,3,8,str);
  357. X              }
  358. X              sput("E-W",1,6);
  359. X              break;
  360. X      case 2: for(ALLp){
  361. X                 rput(p,8,1,0,"N-S ");
  362. X                 str[0]=124-SIDE(p)*79;
  363. X                 rput(p,10,3,8,str);
  364. X              }
  365. X              sput("N-S",1,6);
  366. X              break;
  367. X      case 3: str[0]='+';
  368. X              for(ALLp){
  369. X                 rput(p,8,1,0,"BOTH");
  370. X                 rput(p,10,3,8,str);
  371. X              }
  372. X              sput("BOTH",1,6);
  373. X              break;
  374. X   }
  375. X   for(ALLp){
  376. X      rput(p,9,0,0,"    0");
  377. X      rput(p,9,0,6,"    0");
  378. X      clearw(p,0);clearw(p,1);clearw(p,2);clearw(p,3);
  379. X      clearw(p,4);clearw(p,5);clearw(p,6);clearw(p,7);
  380. X   }
  381. X}
  382. Xpscr()
  383. X{   int i,j;
  384. X    char *d;
  385. X
  386. X    for(i=0;i<16;++i){
  387. X       d=(char *)&scr[i][0];
  388. X       for(j=0;j<80;++j)fprintf(f1,"%c",*d++);
  389. X       fprintf(f1,"\n");
  390. X    }
  391. X    fprintf(f1,"\n\n\n\n");
  392. X    fflush(f1);
  393. X}
  394. X
  395. Xsput(s,r,c)
  396. Xchar *s;
  397. Xint r,c;
  398. X{   char *d;
  399. X
  400. X    d=(char *)&scr[r][c];
  401. X    while(*s) *d++ = *s++;
  402. X}
  403. Xdeal()
  404. X{  int i,j,rr,cc;
  405. X   char *d;
  406. X
  407. X   for(i=0;i<52;++i){
  408. X      card[i]=i;
  409. X      for(j=0;j<4;++j)C[j][i]=0;
  410. X   }
  411. X   for(i=0;i<4;++i){
  412. X      LS[i]=0;
  413. X      for(j=0;j<4;++j) NS[i][j]=0;
  414. X   }
  415. X   i=52;
  416. X   while(i>1){
  417. X      j=random()%i--;
  418. X      C[i/13][card[j]]=1;
  419. X      NS[i/13][card[j]/13]++;
  420. X      if(NS[i/13][card[j]/13]>LS[i/13]) LS[i/13]++;
  421. X      card[j]=card[i];
  422. X   }
  423. X   C[0][card[0]]=1;
  424. X   NS[0][card[0]/13]++;
  425. X   for(i=0;i<4;++i) printhand(i,i);
  426. X   for(i=0;i<4;++i){
  427. X      rr=r[i]-1;cc=c[i]; if(i EQ 3) cc=cc+10-LS[i];
  428. X      for(j=51;j>=0;--j){
  429. X         if(j%13 EQ 12){ d=(char *)&scr[++rr][cc];*d++ =SV[j/13]; *d++ = ' ';}
  430. X         if(C[i][j] EQ 1)*d++ = FV[j%13];
  431. X      }
  432. X   }
  433. X}
  434. Xbid()
  435. X{  int i,j,p,rb,eofb,legalbid,NP,OB;
  436. X   int PFBS[2][5];
  437. X
  438. X   for(ALLp){
  439. X      rput(p,10,2,0,"-----------");
  440. X      rput(p,10,4,6,"-----------");
  441. X      for(i=0;i<=3;++i) rput(p,10,i,11,"|");
  442. X      for(i=0;i<=3;++i) rput(p,10,i+3,5,"|");
  443. X   }
  444. X   for(i=0;i<2;++i)for(j=0;j<5;++j)PFBS[i][j]= -1;
  445. X   rb=HBR=NP=0;
  446. X   eofb=eofg=FALSE;
  447. X   HBS= -1;
  448. X   for(i=OB=hand%4;NOT eofb;i=NEXT(i)){
  449. X      legalbid=FALSE;
  450. X      do{
  451. X         if(readbid(i)<0)continue;
  452. X         if(CBS EQ 6){
  453. X            if((dbl NEQ 1) OR (SIDE(i) NEQ SIDE(HBB)) OR (HBR<1))continue;
  454. X            dbl=2;ldd=i;
  455. X         }
  456. X         if(CBS EQ 5){
  457. X            if((dbl NEQ 0) OR (SIDE(i) EQ SIDE(HBB)) OR (HBR<1))continue;
  458. X            dbl=1;ld=i;
  459. X         }
  460. X         if(CBR<HBR)continue;
  461. X         if(CBR>=HBR AND CBR<8){
  462. X            if ((CBR EQ HBR) AND (CBS<=HBS))continue;
  463. X            dbl=0;HBR=CBR;HBS=CBS;HBB=i;
  464. X            if(PFBS[SIDE(i)][CBS] EQ -1)PFBS[SIDE(i)][CBS]=i;
  465. X         }
  466. X         if(CBS EQ 7) NP++; else NP=0;
  467. X         legalbid=TRUE;
  468. X      }while(NOT legalbid);
  469. X      if(NP EQ 4){eofb=eofg=TRUE;inp[0]=inp[1]='=';}
  470. X      if((NP EQ 3) AND (HBR>0)) {eofb=TRUE;inp[0]=inp[1]='=';}
  471. X      printbid(rb,i);
  472. X      sput(inp,2+rb+(i<OB),47+3*(i%4));
  473. X      if(NEXT(i) EQ OB) rb++;
  474. X   }
  475. X   decl=PFBS[SIDE(HBB)][HBS];
  476. X   dummy=PARTNER(decl);
  477. X   trump=HBS;
  478. X   if(NOT eofg){
  479. X      strcpy(str,"CONTRACT: ");
  480. X      str[10]=HBR+'0'; str[11]=SV[HBS]; str[12]='/'; str[13]=P[decl]; j=14;
  481. X      if(dbl>0){str[j++]=' ';str[j++]='X';str[j++]='/';str[j++]=P[ld];}
  482. X      if(dbl>1)
  483. X         {str[j++]=' ';str[j++]='X';str[j++]='X';str[j++]='/';str[j++]=P[ldd];}
  484. X      str[j]='\0';
  485. X      for(ALLp)rput(p,11,0,0,str);
  486. X      sput(str+10,4+rb,47);
  487. X   }
  488. X}
  489. Xplay()
  490. X{  int r,i,ss,legalplay,winner,FL,FPS,HPR,HPS,p;
  491. X
  492. X   FL=NEXT(decl);
  493. X   win[0]=win[1]=0;
  494. X   for(r=1;r<=13;++r){
  495. X      i=FL;
  496. X      do{
  497. X         legalplay=FALSE;
  498. X         do{
  499. X            if(readplay(i EQ dummy ? decl : i,i)<0)continue;
  500. X            if(CPS EQ 5){
  501. X               if(SIDE(i) NEQ SIDE(decl))continue;
  502. X               if(CPR<0 OR CPR>13-win[0]-win[1])continue;
  503. X               printhand(NEXT(decl),decl);
  504. X               printhand(NEXT(decl),NEXT(dummy));
  505. X               printhand(NEXT(dummy),decl);
  506. X               printhand(NEXT(dummy),NEXT(decl));
  507. X               strcpy(inp,"Declarer asks    more tricks.  Agree?");
  508. X               if(CPR>9) inp[14]='1';
  509. X               inp[15]=CPR%10+'0';
  510. X               rget((1<<NEXT(decl))|(1<<NEXT(dummy)),inp);
  511. X               if(inp[0] NEQ 'Y'){
  512. X                  clearw(NEXT(decl),0);
  513. X                  clearw(NEXT(decl),1);
  514. X                  clearw(NEXT(dummy),3);
  515. X                  clearw(NEXT(dummy),0);
  516. X                  continue;
  517. X               }
  518. X               printhand(decl,NEXT(decl));
  519. X               printhand(decl,NEXT(dummy));
  520. X               win[SIDE(decl)]+=CPR;
  521. X               win[1-SIDE(decl)]=13-win[SIDE(decl)];
  522. X               itos(win[0]);for(ALLp)rput(p,9,0,0,num);
  523. X               itos(win[1]);for(ALLp)rput(p,9,0,6,num);
  524. X               for(ALLp){clearw(p,4);clearw(p,5);clearw(p,6);clearw(p,7);}
  525. X               return;
  526. X            }
  527. X            if(i EQ FL){
  528. X               if(CPS EQ 4) continue;
  529. X               if(CPS EQ 6){
  530. X           if (r < 13) continue;
  531. X                   else{
  532. X                      for(ss=0;C[i][ss]<1;++ss);
  533. X                      inp[0]=SV[CPS=ss/13];inp[1]=FV[CPR=ss%13];
  534. X                   }
  535. X           }
  536. X               if(NOT inhand(CPS,CPR,i))continue;
  537. X               if(r EQ 1){
  538. X                  for(ALLp) clearw(p,10);
  539. X                  for(p=NEXT(dummy);p NEQ dummy;p=NEXT(p))printhand(p,dummy);
  540. X                  printhand(dummy,decl);
  541. X               }
  542. X               winner=FL;
  543. X               HPR=CPR;
  544. X               FPS=HPS=CPS;
  545. X            }
  546. X            else{
  547. X               if(CPS EQ 6){
  548. X                  for(ss=NS[i][FPS]?FPS*13:0;C[i][ss]<1;++ss);
  549. X                  inp[0]=SV[CPS=ss/13];inp[1]=FV[CPR=ss%13];
  550. X               }
  551. X               if(CPS EQ 4) {CPS=FPS;inp[1]=inp[0];inp[0]=SV[FPS];}
  552. X               if((CPS NEQ FPS) AND (NS[i][FPS] NEQ 0))continue;
  553. X               if(NOT inhand(CPS,CPR,i))continue;
  554. X               if(CPS EQ HPS){
  555. X                  if(CPR>HPR){winner=i;HPR=CPR;}
  556. X               }
  557. X               else {if(CPS EQ trump){winner=i;HPR=CPR;HPS=CPS;}}
  558. X            }
  559. X            printplay(i);
  560. X            printsuit(i,i,CPS);
  561. X            sput(inp,1+r,61+4*i);
  562. X            sput("!",1+r,63+4*FL);
  563. X            if(i EQ dummy)
  564. X               for(p=NEXT(dummy);p NEQ dummy;p=NEXT(p))printsuit(p,i,CPS);
  565. X            if(i EQ decl) printsuit(dummy,decl,CPS);
  566. X            legalplay=TRUE;
  567. X         }while(NOT legalplay);
  568. X         i=NEXT(i);
  569. X      }while(i NEQ FL);
  570. X      itos(++win[SIDE(FL=winner)]);
  571. X      for(ALLp) rput(p,9,0,6*SIDE(FL),num);
  572. X      sput("*",r+1,63+4*winner);
  573. X      if(r<13){
  574. X         waitkey("Press return to pause.");
  575. X         for(ALLp){clearw(p,4);clearw(p,5);clearw(p,6);clearw(p,7);}
  576. X      }
  577. X   }
  578. X}
  579. Xscore()
  580. X{  int vt,over,otv,winside;
  581. X
  582. X   vt=VUL[winside=SIDE(decl)][hand%16];
  583. X   over=win[winside]-6-HBR;
  584. X   otv=TV[HBS];
  585. X   if(dbl>0) otv=100*dbl*(vt+1);
  586. X   if(over>=0){
  587. X      rs=HBR*TV[HBS];
  588. X      if(HBS EQ 4) rs+=10;
  589. X      if(dbl NEQ 0) rs=rs*2*dbl;
  590. X      if(rs>=100)rs+=(250+200*vt);
  591. X      rs+=(50+over*otv);
  592. X      if(dbl NEQ 0)rs+=50; 
  593. X      if(HBR EQ 6)rs+=500+250*vt;
  594. X      if(HBR EQ 7)rs+=1000+500*vt;
  595. X   }
  596. X   else{
  597. X      if(dbl EQ 0)rs=50*over*(vt+1);
  598. X      else rs=((200*over+100)+100*over*vt)*dbl;
  599. X   }
  600. X   if(rs<0){winside=1-winside;rs= -rs;}
  601. X   ts[winside]+=rs;
  602. X   printscore(winside);
  603. X   itos(over);sput(num+3,15,55);
  604. X   waitkey("Press return to pause.");
  605. X}
  606. Xrscore()
  607. X{  int over,otv,winside,p;
  608. X
  609. X   winside=SIDE(decl);
  610. X   over=win[winside]-6-HBR;
  611. X   otv=TV[HBS];
  612. X   if(dbl>0) otv=100*dbl*(vt[winside]+1);
  613. X   if(over>=0){
  614. X      rs=HBR*TV[HBS];
  615. X      if(HBS EQ 4) rs+=10;
  616. X      if(dbl NEQ 0) rs=rs*2*dbl;
  617. X      ts[winside]+=rs;
  618. X      ts[winside]+=(over*otv);
  619. X      if(dbl NEQ 0)ts[winside]+=50; 
  620. X      if(HBR EQ 6)ts[winside]+=500+250*vt[winside];
  621. X      if(HBR EQ 7)ts[winside]+=1000+500*vt[winside];
  622. X      part[winside]+=rs;
  623. X      if(part[winside]>=100){
  624. X         if(vt[winside]){
  625. X            ts[winside]+=700-200*vt[1-winside]; vt[0]=vt[1]=0;
  626. X            eofr=1;
  627. X         }
  628. X         else{vt[winside]+=1;}
  629. X         part[0]=part[1]=0; for(ALLp)rput(p,9,1,0,"    0     0");
  630. X      }
  631. X      else{itos(part[winside]);for(ALLp)rput(p,9,1,6*winside,num);}
  632. X      itos(ts[winside]);for(ALLp)rput(p,9,2,6*winside,num);
  633. X   }
  634. X   else{
  635. X      if(dbl EQ 0)rs=50*over*(vt[winside]+1);
  636. X      else rs=((200*over+100)+100*over*vt[winside])*dbl;
  637. X      ts[1-winside]-=rs;
  638. X      itos(ts[1-winside]);for(ALLp)rput(p,9,2,6-6*winside,num);
  639. X   }
  640. X   itos(over);sput(num+3,15,55);
  641. X   waitkey("Press return to pause.");
  642. X}
  643. Xreadbid(i)
  644. Xint i;
  645. X{   
  646. X   strcpy(inp,"It's your turn to bid ");
  647. X   rget(1<<i,inp);
  648. X   inp[2]='\0'; 
  649. X   CBR=inp[0]-'0';
  650. X   if(CBR>0 AND CBR <8) return(CBS=lookup(inp[1],SV,5));
  651. X   CBR=8;
  652. X   switch(inp[0]){
  653. X      case '\n':
  654. X      case 'P': inp[0]=inp[1]='-';CBS=7;return(CBS);
  655. X      case 'X': if(inp[1] EQ 'X'){CBS=6;return(CBS);}
  656. X                else{inp[1]='\0';CBS=5;return(CBS);}
  657. X      default:  return(-1);
  658. X   }
  659. X}
  660. Xreadplay(i,j)
  661. Xint i,j;
  662. X{
  663. X   if (j EQ dummy) strcpy(inp,"It's dummy's turn to play ");
  664. X   else strcpy(inp,"It's your turn to play ");
  665. X   rget(1<<i,inp);
  666. X   if(inp[0] EQ 'F'){
  667. X     CPS=5;CPR=inp[1]-'0';
  668. X     if(inp[2]>='0' AND inp[2]<='9') CPR=CPR*10+inp[2]-'0';
  669. X     if(inp[1]=='\n') CPR=13-win[0]-win[1];
  670. X     return(0);
  671. X     }
  672. X   inp[2]='\0'; 
  673. X   if((CPR=lookup(inp[0],FV,13))>=0) {CPS=4;return(0);}
  674. X   if(inp[0] EQ '\n'){CPS=6;return(0);}
  675. X   CPS=lookup(inp[0],SV,4);
  676. X   CPR=lookup(inp[1],FV,13);
  677. X   if(CPS<0 OR CPR<0) return(-1);
  678. X   else return(0);
  679. X}
  680. Xlookup(ch,t,i)
  681. Xint i;
  682. Xchar ch,*t;
  683. X
  684. X{  int j;
  685. X   for(j=i-1;j>=0;j--)if(ch EQ t[j]) return(j);
  686. X   return(-1);
  687. X}
  688. Xinhand(s,r,i)
  689. Xint s,r,i;
  690. X
  691. X{  int j;
  692. X
  693. X   j=s*13+r;
  694. X   if(C[i][j] NEQ 1)return(FALSE);
  695. X   C[i][j]=0;
  696. X   NS[i][s]--;
  697. X   return(TRUE);
  698. X}
  699. Xitos(i)
  700. Xint i;
  701. X
  702. X{  int j,f;
  703. X   char t;
  704. X
  705. X   if(i EQ 0) {num[0]=num[1]=num[2]=num[3]=' ';num[4]='0';num[5]=0;return;}
  706. X   f=0;if(i<0){f=1;i= -i;}
  707. X   num[0]='\0';
  708. X   for(j=1;j<=5;j++)
  709. X      if(i>0){
  710. X         num[j]=i%10+'0';
  711. X         i/=10;
  712. X      }
  713. X      else{ if(f){num[j]='-';f=0;} else num[j]=' ';}
  714. X   for(i=0;i<=2;++i){
  715. X      t=num[i];
  716. X      num[i]=num[5-i];
  717. X      num[5-i]=t;
  718. X   }
  719. X}
  720. Xprinthand(p,h)
  721. Xint p,h;
  722. X
  723. X{  int s;
  724. X
  725. X   for(s=0;s<4;++s)printsuit(p,h,s);
  726. X}
  727. Xprintsuit(p,h,s)
  728. Xint p,h,s;
  729. X
  730. X{  int i,j=2,offset=0;
  731. X   str[0]=SV[s];
  732. X   str[1]=' ';
  733. X   for(i=12;i>=0;--i)if(C[h][s*13+i] EQ 1)str[j++]=FV[i];
  734. X   str[j++]=' ';str[j]='\0';
  735. X   if((j=(6+h-p)%4) EQ 3) offset=11-LS[h];
  736. X   rput(p,j,3-s,offset,str);
  737. X}
  738. Xprintplay(h)
  739. Xint h;
  740. X
  741. X{  int p;
  742. X
  743. X   for(ALLp) rput(p,(6+h-p)%4+4,0,0,inp);
  744. X}
  745. Xprintscore(winside)
  746. Xint winside;
  747. X
  748. X{ int p;
  749. X
  750. X  itos(rs);for(ALLp){rput(p,9,1,6*winside,num);rput(p,9,1,6-6*winside,"    0");}
  751. X  sput(num,15,69);
  752. X  itos(ts[winside]);for(ALLp)rput(p,9,2,6*winside,num);
  753. X}
  754. Xprintbid(rb,i)
  755. Xint rb,i;
  756. X{  int p;
  757. X   p=i;
  758. X   rput(p,10,5+rb/4,6+3*(rb%4),inp); p=NEXT(p);
  759. X   rput(p,10,3-rb%4,12+3*(rb/4),inp); p=NEXT(p);
  760. X   rput(p,10,1-rb/4,9-3*(rb%4),inp); p=NEXT(p);
  761. X   rput(p,10,3+rb%4,3-3*(rb/4),inp); p=NEXT(p);
  762. X}
  763. Xwaitkey(c)
  764. Xchar *c;
  765. X{  int p;
  766. X   char t[40];
  767. X   do {strcpy(t,c);}
  768. X   while(rwait((1<<decl)|(1<<NEXT(decl))|(1<<NEXT(dummy)),t,2)>0);
  769. X   for(ALLp) clearw(p,12);
  770. X}
  771. Xclearw(p,wn)
  772. Xint p,wn;
  773. X
  774. X{  
  775. X   str[0]='Z';
  776. X   str[1]='\0';
  777. X   rput(p,wn,0,0,str);
  778. X}
  779. X/*
  780. Xrput(p,w,r,c,s)
  781. Xint p,w,r,c;
  782. Xchar *s;
  783. X
  784. X{   printf("p=%d, w=%d, r=%d, c=%d, s=%s",p,w,r,c,s);
  785. X}
  786. Xrget(p,s)
  787. Xint p;
  788. Xchar *s;
  789. X{   scanf("%s",s);
  790. X}
  791. X*/
  792. Xmore()
  793. X{  int p;
  794. X/*
  795. X   if(NOT eofr) return;
  796. X   strcpy(inp,"You like another rubber?");
  797. X   rwait(15,inp,5);
  798. X   if(inp[0] NEQ 'Y'){for(ALLp)rput(p,0,0,0,"\\"); exit();}
  799. X   for(ALLp)clearw(p,12);
  800. X   eofr=0;
  801. X*/
  802. X   return;
  803. X}
  804. Xbridge()
  805. X{  int p;
  806. X
  807. X   init();
  808. X   eofp=FALSE;
  809. X   do{
  810. X      rinit();
  811. X      deal();
  812. X      bid();
  813. X      if(NOT eofg){
  814. X         play();
  815. X         rscore();
  816. X      }
  817. X      else for(ALLp) clearw(p,10);
  818. X      pscr();
  819. X      more();
  820. X   }while(NOT eofp);
  821. X}
  822. END_OF_bridge.c
  823. if test 14041 -ne `wc -c <bridge.c`; then
  824.     echo shar: \"bridge.c\" unpacked with wrong size!
  825. fi
  826. # end of overwriting check
  827. fi
  828. if test -f ctl_transact.c -a "${1}" != "-c" ; then 
  829.   echo shar: Will not over-write existing file \"ctl_transact.c\"
  830. else
  831. echo shar: Extracting \"ctl_transact.c\" \(2210 characters\)
  832. sed "s/^X//" >ctl_transact.c <<'END_OF_ctl_transact.c'
  833. X#ifndef lint
  834. Xstatic    char sccsid[] = "@(#)ctl_transact.c 1.1 86/02/05 SMI"; /* from UCB */
  835. X#endif
  836. X#include "talk_ctl.h"
  837. X#include <sys/time.h>
  838. X
  839. X#define CTL_WAIT 2    /* the amount of time to wait for a 
  840. X               response, in seconds */
  841. X
  842. X
  843. X    /*
  844. X     * SOCKDGRAM is unreliable, so we must repeat messages if we have
  845. X     * not recieved an acknowledgement within a reasonable amount
  846. X     * of time
  847. X     */
  848. X
  849. Xctl_transact(target, msg, type, response)
  850. Xstruct in_addr target;
  851. XCTL_MSG msg;
  852. Xint type;
  853. XCTL_RESPONSE *response;
  854. X{
  855. X    struct sockaddr junk;
  856. X    int read_mask;
  857. X    int ctl_mask;
  858. X    int nready;
  859. X    int cc;
  860. X    int junk_size;
  861. X    struct timeval wait;
  862. X
  863. X    wait.tv_sec = CTL_WAIT;
  864. X    wait.tv_usec = 0;
  865. X
  866. X    msg.type = type;
  867. X
  868. X    daemon_addr.sin_addr = target;
  869. X    daemon_addr.sin_port = daemon_port;
  870. X
  871. X    ctl_mask = 1 << ctl_sockt;
  872. X
  873. X    /*
  874. X     * keep sending the message until a response of the right
  875. X     * type is obtained
  876. X     */
  877. X    do {
  878. X        /* keep sending the message until a response is obtained */
  879. X
  880. X    do {
  881. X        cc = sendto(ctl_sockt, (char *)&msg, sizeof(CTL_MSG), 0,
  882. X            &daemon_addr, sizeof(daemon_addr));
  883. X
  884. X        if (cc != sizeof(CTL_MSG)) {
  885. X        if (errno == EINTR) {
  886. X            /* we are returning from an interupt */
  887. X            continue;
  888. X        } else {
  889. X            p_error("Error on write to talk daemon");
  890. X        }
  891. X        }
  892. X
  893. X        read_mask = ctl_mask;
  894. X
  895. X        while ((nready = select(32, &read_mask, 0, 0, &wait)) < 0) {
  896. X        if (errno == EINTR) {
  897. X            /* we are returning from an interupt */
  898. X            continue;
  899. X        } else {
  900. X            p_error("Error on waiting for response from daemon");
  901. X        }
  902. X        }
  903. X    } while (nready == 0);
  904. X
  905. X        /* keep reading while there are queued messages 
  906. X           (this is not necessary, it just saves extra
  907. X           request/acknowledgements being sent)
  908. X         */
  909. X
  910. X    do {
  911. X
  912. X        junk_size = sizeof(junk);
  913. X        cc = recvfrom(ctl_sockt, (char *) response,
  914. X               sizeof(CTL_RESPONSE), 0, &junk, &junk_size );
  915. X        if (cc < 0) {
  916. X        if (errno == EINTR) {
  917. X            continue;
  918. X        }
  919. X        p_error("Error on read from talk daemon");
  920. X        }
  921. X
  922. X        read_mask = ctl_mask;
  923. X
  924. X        /* an immediate poll */
  925. X
  926. X        timerclear(&wait);
  927. X        nready = select(32, &read_mask, 0, 0, &wait);
  928. X
  929. X    } while ( nready > 0 && response->type != type);
  930. X
  931. X    } while (response->type != type);
  932. X}
  933. END_OF_ctl_transact.c
  934. if test 2210 -ne `wc -c <ctl_transact.c`; then
  935.     echo shar: \"ctl_transact.c\" unpacked with wrong size!
  936. fi
  937. # end of overwriting check
  938. fi
  939. if test -f init_disp.c -a "${1}" != "-c" ; then 
  940.   echo shar: Will not over-write existing file \"init_disp.c\"
  941. else
  942. echo shar: Extracting \"init_disp.c\" \(6607 characters\)
  943. sed "s/^X//" >init_disp.c <<'END_OF_init_disp.c'
  944. X#ifndef lint
  945. Xstatic    char sccsid[] = "@(#)init_disp.c 1.1 86/02/05 SMI"; /* from UCB 1.2 83/06/23 */
  946. X#endif
  947. X
  948. X/*
  949. X * init_disp contains the initialization code for the display package,
  950. X * as well as the signal handling routines
  951. X */
  952. X
  953. X#include "talk.h"
  954. X#include <signal.h>
  955. X
  956. Xextern int    ID;
  957. Xint    curses_initialized;
  958. X
  959. X/* 
  960. X * set up curses, catch the appropriate signals, and build the
  961. X * various windows
  962. X */
  963. X
  964. Xinit_disp()
  965. X{    int i, t;
  966. X
  967. X    void sig_sent();
  968. X
  969. X    initscr();
  970. X    curses_initialized = 1;
  971. X
  972. X    clear();
  973. X    refresh();
  974. X
  975. X    noecho();
  976. X    crmode();
  977. X
  978. X    signal(SIGINT, sig_sent);
  979. X    signal(SIGPIPE, sig_sent);
  980. X
  981. X    /* curses takes care of ^Z */
  982. X
  983. X    comwin[0].x_nlines = 4;
  984. X    comwin[0].x_ncols = 15;
  985. X    comwin[0].x_win = newwin(4, 15, 0, 22);
  986. X    
  987. X    comwin[1].x_nlines = 4;
  988. X    comwin[1].x_ncols = 15;
  989. X    comwin[1].x_win = newwin(4, 15, 6, 40);
  990. X    
  991. X    comwin[2].x_nlines = 4;
  992. X    comwin[2].x_ncols = 15;
  993. X    comwin[2].x_win = newwin(4, 15, 13, 22);
  994. X    
  995. X    comwin[3].x_nlines = 4;
  996. X    comwin[3].x_ncols = 15;
  997. X    comwin[3].x_win = newwin(4, 15, 6, 5);
  998. X    
  999. X    comwin[4].x_nlines = 1;
  1000. X    comwin[4].x_ncols = 2;
  1001. X    comwin[4].x_win = newwin(1, 2, 5, 28);
  1002. X    
  1003. X    comwin[5].x_nlines = 1;
  1004. X    comwin[5].x_ncols = 2;
  1005. X    comwin[5].x_win = newwin(1, 2, 8, 35);
  1006. X    
  1007. X    comwin[6].x_nlines = 1;
  1008. X    comwin[6].x_ncols = 2;
  1009. X    comwin[6].x_win = newwin(1, 2, 11, 28);
  1010. X    
  1011. X    comwin[7].x_nlines = 1;
  1012. X    comwin[7].x_ncols = 2;
  1013. X    comwin[7].x_win = newwin(1, 2, 8, 22);
  1014. X    
  1015. X    comwin[8].x_nlines = 2;
  1016. X    comwin[8].x_ncols = 4;
  1017. X    comwin[8].x_win = newwin(2, 4, 1, 7);
  1018. X    
  1019. X    comwin[9].x_nlines = 3;
  1020. X    comwin[9].x_ncols = 11;
  1021. X    comwin[9].x_win = newwin(3, 11, 5, 67);
  1022. X    
  1023. X    comwin[10].x_nlines = 7;
  1024. X    comwin[10].x_ncols = 17;
  1025. X    comwin[10].x_win = newwin(7, 17, 5, 21);
  1026. X    
  1027. X    comwin[11].x_nlines = 1;
  1028. X    comwin[11].x_ncols = 30;
  1029. X    comwin[11].x_win = newwin(1, 30, 1, 50);
  1030. X    comwin[12].x_nlines = 1;
  1031. X    comwin[12].x_ncols = 40;
  1032. X    comwin[12].x_win = newwin(1, 40, 16, 40);
  1033. X    
  1034. X    comwin[13].x_nlines = 24;
  1035. X    comwin[13].x_ncols = 80;
  1036. X    comwin[13].x_win = newwin(24, 80, 0, 0);
  1037. X    
  1038. X    comwin[14].x_nlines = 5;
  1039. X    comwin[14].x_ncols = 19;
  1040. X    comwin[14].x_win = newwin(5, 19, 18, 0);
  1041. X    
  1042. X    comwin[15].x_nlines = 5;
  1043. X    comwin[15].x_ncols = 19;
  1044. X    comwin[15].x_win = newwin(5, 19, 18, 20);
  1045. X    
  1046. X    comwin[16].x_nlines = 5;
  1047. X    comwin[16].x_ncols = 19;
  1048. X    comwin[16].x_win = newwin(5, 19, 18, 40);
  1049. X    
  1050. X    comwin[17].x_nlines = 5;
  1051. X    comwin[17].x_ncols = 19;
  1052. X    comwin[17].x_win = newwin(5, 19, 18, 60);
  1053. X    
  1054. X    comwin[18].x_nlines = 1;
  1055. X    comwin[18].x_ncols = 20;
  1056. X    comwin[18].x_win = newwin(1, 20, 16, 0);
  1057. X    for (i=0; i<19; i++){ 
  1058. X        scrollok(comwin[i].x_win, FALSE);
  1059. X        wclear(comwin[i].x_win);
  1060. X    };
  1061. Xfor (i=14; i<18;++i) scrollok(comwin[i].x_win, TRUE);
  1062. X    wmove(comwin[13].x_win, 1, 1);
  1063. X    wprintw(comwin[13].x_win, "HAND:");
  1064. X    wmove(comwin[13].x_win, 2, 1);
  1065. X    wprintw(comwin[13].x_win, "VUL.:");
  1066. X    wmove(comwin[13].x_win, 4, 20);
  1067. X    wprintw(comwin[13].x_win, "-------------------");
  1068. X    wmove(comwin[13].x_win, 5, 20);
  1069. X    wprintw(comwin[13].x_win, "|");
  1070. X    wmove(comwin[13].x_win, 6, 20);
  1071. X    wprintw(comwin[13].x_win, "|");
  1072. X    wmove(comwin[13].x_win, 7, 20);
  1073. X    wprintw(comwin[13].x_win, "|");
  1074. X    wmove(comwin[13].x_win, 8, 20);
  1075. X    wprintw(comwin[13].x_win, "|");
  1076. X    wmove(comwin[13].x_win, 9, 20);
  1077. X    wprintw(comwin[13].x_win, "|");
  1078. X    wmove(comwin[13].x_win, 10, 20);
  1079. X    wprintw(comwin[13].x_win, "|");
  1080. X    wmove(comwin[13].x_win, 11, 20);
  1081. X    wprintw(comwin[13].x_win, "|");
  1082. X    wmove(comwin[13].x_win, 12, 20);
  1083. X    wprintw(comwin[13].x_win, "-------------------");
  1084. X    wmove(comwin[13].x_win, 5, 38);
  1085. X    wprintw(comwin[13].x_win, "|");
  1086. X    wmove(comwin[13].x_win, 6, 38);
  1087. X    wprintw(comwin[13].x_win, "|");
  1088. X    wmove(comwin[13].x_win, 7, 38);
  1089. X    wprintw(comwin[13].x_win, "|");
  1090. X    wmove(comwin[13].x_win, 8, 38);
  1091. X    wprintw(comwin[13].x_win, "|");
  1092. X    wmove(comwin[13].x_win, 9, 38);
  1093. X    wprintw(comwin[13].x_win, "|");
  1094. X    wmove(comwin[13].x_win, 10, 38);
  1095. X    wprintw(comwin[13].x_win, "|");
  1096. X    wmove(comwin[13].x_win, 11, 38);
  1097. X    wprintw(comwin[13].x_win, "|");
  1098. X    wmove(comwin[13].x_win, 3, 68);
  1099. X    wprintw(comwin[13].x_win, "N-S   E-W");
  1100. X    wmove(comwin[13].x_win, 4, 67);
  1101. X    wprintw(comwin[13].x_win, "----- -----");
  1102. X    wmove(comwin[13].x_win, 5, 60);
  1103. X    wprintw(comwin[13].x_win, "TRICK:     0     0");
  1104. X    wmove(comwin[13].x_win, 6, 60);
  1105. X    wprintw(comwin[13].x_win, "SCORE:     0     0");
  1106. X    wmove(comwin[13].x_win, 7, 60);
  1107. X    wprintw(comwin[13].x_win, "TOTAL:     0     0");
  1108. X    wmove(comwin[13].x_win, 9, 55);
  1109. X    wprintw(comwin[13].x_win, "ABBREVIATIONS --");
  1110. X    wmove(comwin[13].x_win, 10, 57);
  1111. X    wprintw(comwin[13].x_win, "P:PASS     N:NO TRUMP");
  1112. X    wmove(comwin[13].x_win, 11, 57);
  1113. X    wprintw(comwin[13].x_win, "S:SPADE    H:HEART");
  1114. X    wmove(comwin[13].x_win, 12, 57);
  1115. X    wprintw(comwin[13].x_win, "D:DIAMOND  C:CLUB,");
  1116. X    wmove(comwin[13].x_win, 13, 57);
  1117. X    wprintw(comwin[13].x_win, "X:DOUBLE  XX:REDOUBLE");
  1118. X    wmove(comwin[13].x_win, 14, 57);
  1119. X    wprintw(comwin[13].x_win, "T:10      F#:Finish");
  1120. X    wmove(comwin[13].x_win, 17,0);
  1121. X    wprintw(comwin[13].x_win, "--------------------------------------------------------------------------------");
  1122. X    wmove(comwin[13].x_win, 18,19);
  1123. X    wprintw(comwin[13].x_win, "|");
  1124. X    wmove(comwin[13].x_win, 18,39);
  1125. X    wprintw(comwin[13].x_win, "|");
  1126. X    wmove(comwin[13].x_win, 18,59);
  1127. X    wprintw(comwin[13].x_win, "|");
  1128. X    wmove(comwin[13].x_win, 19,19);
  1129. X    wprintw(comwin[13].x_win, "|");
  1130. X    wmove(comwin[13].x_win, 19,39);
  1131. X    wprintw(comwin[13].x_win, "|");
  1132. X    wmove(comwin[13].x_win, 19,59);
  1133. X    wprintw(comwin[13].x_win, "|");
  1134. X    wmove(comwin[13].x_win, 20,19);
  1135. X    wprintw(comwin[13].x_win, "|");
  1136. X    wmove(comwin[13].x_win, 20,39);
  1137. X    wprintw(comwin[13].x_win, "|");
  1138. X    wmove(comwin[13].x_win, 20,59);
  1139. X    wprintw(comwin[13].x_win, "|");
  1140. X    wmove(comwin[13].x_win, 21,19);
  1141. X    wprintw(comwin[13].x_win, "|");
  1142. X    wmove(comwin[13].x_win, 21,39);
  1143. X    wprintw(comwin[13].x_win, "|");
  1144. X    wmove(comwin[13].x_win, 21,59);
  1145. X    wprintw(comwin[13].x_win, "|");
  1146. X    wmove(comwin[13].x_win, 22,19);
  1147. X    wprintw(comwin[13].x_win, "|");
  1148. X    wmove(comwin[13].x_win, 22,39);
  1149. X    wprintw(comwin[13].x_win, "|");
  1150. X    wmove(comwin[13].x_win, 22,59);
  1151. X    wprintw(comwin[13].x_win, "|");
  1152. X    wrefresh(comwin[13].x_win);
  1153. X
  1154. X    current_state = "No connection yet";
  1155. X}
  1156. X
  1157. Xvoid sig_sent()
  1158. X{
  1159. X    message("Connection closing. Exiting");
  1160. X    quit();
  1161. X}
  1162. X
  1163. X/*
  1164. X * All done talking...hang up the phone and reset terminal thingy's
  1165. X */
  1166. X
  1167. Xquit()
  1168. X{       int i;
  1169. X
  1170. X    if (curses_initialized) {
  1171. X        for (i=0; i<3; i++){
  1172. X           wmove(comwin[i].x_win, comwin[i].x_nlines-1, 0);
  1173. X           wclrtoeol(comwin[i].x_win);
  1174. X           wrefresh(comwin[i].x_win);
  1175. X        };
  1176. X        endwin();
  1177. X    }
  1178. X
  1179. X    if (invitation_waiting) {
  1180. X        send_delete();
  1181. X    }
  1182. X
  1183. X    exit(0);
  1184. X}
  1185. END_OF_init_disp.c
  1186. if test 6607 -ne `wc -c <init_disp.c`; then
  1187.     echo shar: \"init_disp.c\" unpacked with wrong size!
  1188. fi
  1189. # end of overwriting check
  1190. fi
  1191. if test -f invite.c -a "${1}" != "-c" ; then 
  1192.   echo shar: Will not over-write existing file \"invite.c\"
  1193. else
  1194. echo shar: Extracting \"invite.c\" \(3759 characters\)
  1195. sed "s/^X//" >invite.c <<'END_OF_invite.c'
  1196. X#ifndef lint
  1197. Xstatic    char sccsid[] = "@(#)invite.c 1.1 86/02/05 SMI"; /* from UCB 1.7 83/07/06 */
  1198. X#endif
  1199. X
  1200. X#include "talk_ctl.h"
  1201. X#include <sys/time.h>
  1202. X#include <signal.h>
  1203. X#include <setjmp.h>
  1204. X    
  1205. X    /*
  1206. X     * there wasn't an invitation waiting, so send a request containing
  1207. X     * our sockt address to the remote talk daemon so it can invite
  1208. X     * him 
  1209. X     */
  1210. X
  1211. Xint local_id, remote_id;    /* the msg.id's for the invitations
  1212. X                   on the local and remote machines.
  1213. X                   These are used to delete the 
  1214. X                   invitations. */
  1215. Xvoid re_invite();
  1216. Xjmp_buf    invitebuf;
  1217. X
  1218. Xinvite_remote()
  1219. X{
  1220. X    int nfd, read_mask, template, new_sockt;
  1221. X    struct itimerval itimer;
  1222. X    CTL_RESPONSE response;
  1223. X
  1224. X    itimer.it_value.tv_sec = RING_WAIT;
  1225. X    itimer.it_value.tv_usec = 0;
  1226. X    itimer.it_interval = itimer.it_value;
  1227. X
  1228. X    if (listen(sockt, 5) != 0) {
  1229. X    p_error("Error on attempt to listen for caller");
  1230. X    }
  1231. X
  1232. X    msg.addr = my_addr;
  1233. X    msg.id_num = -1;        /* an impossible id_num */
  1234. X
  1235. X    invitation_waiting = 1;
  1236. X
  1237. X    announce_invite();
  1238. X
  1239. X    /*
  1240. X     * shut off the automatic messages for a while,
  1241. X     * so we can use the interupt timer to resend the invitation
  1242. X     */
  1243. X
  1244. X    setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
  1245. X    message("Waiting for your party to respond");
  1246. X    signal(SIGALRM, re_invite);
  1247. X    (void) setjmp(invitebuf);
  1248. X
  1249. X    while ((new_sockt = accept(sockt, 0, 0)) < 0) {
  1250. X    if (errno != EINTR) {
  1251. X        p_error("Unable to connect with your party");
  1252. X    } else {
  1253. X        /* we just returned from a interupt, keep trying */
  1254. X        continue;
  1255. X    }
  1256. X    }
  1257. X
  1258. X    close(sockt);
  1259. X    sockt = new_sockt;
  1260. X
  1261. X    /* have the daemons delete the invitations now that we
  1262. X       have connected.
  1263. X     */
  1264. X
  1265. X    current_state = "Waiting for your party to respond";
  1266. X
  1267. X    msg.id_num = local_id;
  1268. X    ctl_transact(my_machine_addr, msg, DELETE, &response);
  1269. X    msg.id_num = remote_id;
  1270. X    ctl_transact(his_machine_addr, msg, DELETE, &response);
  1271. X    invitation_waiting = 0;
  1272. X}
  1273. X
  1274. X    /* routine called on interupt to re-invite the callee */
  1275. X
  1276. Xvoid re_invite()
  1277. X{
  1278. X    message("Ringing your party again");
  1279. X    current_line++;
  1280. X    /* force a re-announce */
  1281. X    msg.id_num = remote_id + 1;
  1282. X    announce_invite();
  1283. X    longjmp(invitebuf, 1);
  1284. X}
  1285. X
  1286. X    /* transmit the invitation and process the response */
  1287. X
  1288. Xannounce_invite()
  1289. X{
  1290. X    CTL_RESPONSE response;
  1291. X
  1292. X    current_state = "Trying to connect to your party's talk daemon";
  1293. X
  1294. X    ctl_transact(his_machine_addr, msg, ANNOUNCE, &response);
  1295. X    remote_id = response.id_num;
  1296. X
  1297. X    if (response.answer != SUCCESS) {
  1298. X
  1299. X    switch (response.answer) {
  1300. X        
  1301. X        case NOT_HERE :
  1302. X        message("Your party is not logged on");
  1303. X        break;
  1304. X
  1305. X        case MACHINE_UNKNOWN :
  1306. X        message("Target machine does not recognize us");
  1307. X        break;
  1308. X
  1309. X        case UNKNOWN_REQUEST :
  1310. X        message("Target machine can not handle remote talk");
  1311. X        break;
  1312. X
  1313. X        case FAILED :
  1314. X        message("Target machine is too confused to talk to us");
  1315. X        break;
  1316. X
  1317. X        case PERMISSION_DENIED :
  1318. X        message("Your party is refusing messages");
  1319. X        break;
  1320. X    }
  1321. X
  1322. X    quit();
  1323. X    }
  1324. X
  1325. X    /* leave the actual invitation on my talk daemon */
  1326. X
  1327. X    ctl_transact(my_machine_addr, msg, LEAVE_INVITE, &response);
  1328. X    local_id = response.id_num;
  1329. X}
  1330. X    
  1331. Xsend_delete()
  1332. X{
  1333. X    /* tell the daemon to remove your invitation */
  1334. X
  1335. X    msg.type = DELETE;
  1336. X
  1337. X    /* this is just a extra clean up, so just send it
  1338. X       and don't wait for an answer */
  1339. X
  1340. X    msg.id_num = remote_id;
  1341. X    daemon_addr.sin_addr = his_machine_addr;
  1342. X    if (sendto(ctl_sockt, &msg, sizeof(CTL_MSG), 0, &daemon_addr,
  1343. X            sizeof(daemon_addr)) != sizeof(CTL_MSG)) {
  1344. X        perror("send_delete remote");
  1345. X    }
  1346. X
  1347. X    msg.id_num = local_id;
  1348. X    daemon_addr.sin_addr = my_machine_addr;
  1349. X    if (sendto(ctl_sockt, &msg, sizeof(CTL_MSG), 0, &daemon_addr,
  1350. X            sizeof(daemon_addr)) != sizeof(CTL_MSG)) {
  1351. X        perror("send_delete local");
  1352. X    }
  1353. X}
  1354. END_OF_invite.c
  1355. if test 3759 -ne `wc -c <invite.c`; then
  1356.     echo shar: \"invite.c\" unpacked with wrong size!
  1357. fi
  1358. # end of overwriting check
  1359. fi
  1360. if test -f look_up.c -a "${1}" != "-c" ; then 
  1361.   echo shar: Will not over-write existing file \"look_up.c\"
  1362. else
  1363. echo shar: Extracting \"look_up.c\" \(3343 characters\)
  1364. sed "s/^X//" >look_up.c <<'END_OF_look_up.c'
  1365. X#ifndef lint
  1366. Xstatic    char sccsid[] = "@(#)look_up.c 1.1 86/02/05 SMI"; /* from UCB 1.2 83/03/28 */
  1367. X#endif
  1368. X
  1369. X#include "talk_ctl.h"
  1370. X
  1371. X    /* see if the local daemon has a invitation for us */
  1372. X
  1373. XCTL_RESPONSE swapresponse();
  1374. X
  1375. Xcheck_local()
  1376. X{
  1377. X    CTL_RESPONSE response;
  1378. X
  1379. X    /* the rest of msg was set up in get_names */
  1380. X
  1381. X    msg.ctl_addr = ctl_addr;
  1382. X
  1383. X    if (!look_for_invite(&response)) {
  1384. X
  1385. X        /* we must be initiating a talk */
  1386. X
  1387. X    return(0);
  1388. X    }
  1389. X
  1390. X        /*
  1391. X     * there was an invitation waiting for us, 
  1392. X     * so connect with the other (hopefully waiting) party 
  1393. X     */
  1394. X
  1395. X    current_state = "Waiting to connect with caller";
  1396. X
  1397. X    response = swapresponse(response);
  1398. X    while (connect(sockt, &response.addr, sizeof(response.addr)) != 0) {
  1399. X    if (errno == ECONNREFUSED) {
  1400. X
  1401. X        /* the caller gave up, but his invitation somehow
  1402. X         * was not cleared. Clear it and initiate an 
  1403. X         * invitation. (We know there are no newer invitations,
  1404. X         * the talkd works LIFO.)
  1405. X         */
  1406. X
  1407. X        ctl_transact(his_machine_addr, msg, DELETE, &response);
  1408. X        close(sockt);
  1409. X        open_sockt();
  1410. X        return(0);
  1411. X    } else if (errno == EINTR) {
  1412. X        /* we have returned from an interupt handler */
  1413. X        continue;
  1414. X    } else {
  1415. X        p_error("Unable to connect with initiator");
  1416. X    }
  1417. X    }
  1418. X
  1419. X    return(1);
  1420. X}
  1421. X
  1422. X    /* look for an invitation on 'machine' */
  1423. X
  1424. Xlook_for_invite(response)
  1425. XCTL_RESPONSE *response;
  1426. X{
  1427. X    struct in_addr machine_addr;
  1428. X
  1429. X    current_state = "Checking for invitation on caller's machine";
  1430. X
  1431. X    ctl_transact(his_machine_addr, msg, LOOK_UP, response);
  1432. X
  1433. X    /* the switch is for later options, such as multiple 
  1434. X       invitations */
  1435. X
  1436. X    switch (response->answer) {
  1437. X
  1438. X    case SUCCESS:
  1439. X
  1440. X        msg.id_num = response->id_num;
  1441. X        return(1);
  1442. X
  1443. X    default :
  1444. X        /* there wasn't an invitation waiting for us */
  1445. X        return(0);
  1446. X    }
  1447. X}
  1448. X
  1449. X/*  
  1450. X * heuristic to detect if need to reshuffle CTL_RESPONSE structure
  1451. X */
  1452. X
  1453. X#define swapshort(a) (((a << 8) | ((unsigned short) a >> 8)) & 0xffff)
  1454. X#define swaplong(a) ((swapshort(a) << 16) | (swapshort(((unsigned)a >> 16))))
  1455. X
  1456. X#ifdef sun
  1457. Xstruct ctl_response_vax {
  1458. X    char type;
  1459. X    char answer;
  1460. X    short junk;
  1461. X    int id_num;
  1462. X    struct sockaddr_in addr;
  1463. X};
  1464. X
  1465. XCTL_RESPONSE
  1466. Xswapresponse(rsp)
  1467. X    CTL_RESPONSE rsp;
  1468. X{
  1469. X    struct ctl_response_vax swaprsp;
  1470. X    
  1471. X    if (rsp.addr.sin_family != AF_INET) {
  1472. X        bcopy(&rsp, &swaprsp, sizeof(CTL_RESPONSE));
  1473. X        swaprsp.addr.sin_family = swapshort(swaprsp.addr.sin_family);
  1474. X        if (swaprsp.addr.sin_family == AF_INET) {
  1475. X            rsp.addr = swaprsp.addr;
  1476. X            rsp.type = swaprsp.type;
  1477. X            rsp.answer = swaprsp.answer;
  1478. X            rsp.id_num = swaplong(swaprsp.id_num);
  1479. X        }
  1480. X    }
  1481. X    return rsp;
  1482. X}
  1483. X#endif
  1484. X
  1485. X#ifdef vax
  1486. Xstruct ctl_response_sun {
  1487. X    char type;
  1488. X    char answer;
  1489. X    unsigned short id_num2;
  1490. X    unsigned short id_num1;
  1491. X    short sin_family;
  1492. X    short sin_port;
  1493. X    short sin_addr2;
  1494. X    short sin_addr1;
  1495. X};
  1496. X
  1497. XCTL_RESPONSE
  1498. Xswapresponse(rsp)
  1499. X    CTL_RESPONSE rsp;
  1500. X{
  1501. X    struct ctl_response_sun swaprsp;
  1502. X    
  1503. X    if (rsp.addr.sin_family != AF_INET) {
  1504. X        bcopy(&rsp, &swaprsp, sizeof(struct ctl_response_sun));
  1505. X        if (swaprsp.sin_family == swapshort(AF_INET)) {
  1506. X            rsp.type = swaprsp.type;
  1507. X            rsp.answer = swaprsp.answer;
  1508. X            rsp.id_num = swapshort(swaprsp.id_num1)
  1509. X                | (swapshort(swaprsp.id_num2) << 16);
  1510. X            rsp.addr.sin_family = swapshort(swaprsp.sin_family);
  1511. X            rsp.addr.sin_port = swaprsp.sin_port;
  1512. X            rsp.addr.sin_addr.s_addr =
  1513. X                swaprsp.sin_addr2 | (swaprsp.sin_addr1 << 16);
  1514. X        }
  1515. X    }
  1516. X    return rsp;
  1517. X}
  1518. X#endif
  1519. END_OF_look_up.c
  1520. if test 3343 -ne `wc -c <look_up.c`; then
  1521.     echo shar: \"look_up.c\" unpacked with wrong size!
  1522. fi
  1523. # end of overwriting check
  1524. fi
  1525. if test -f master_io.c -a "${1}" != "-c" ; then 
  1526.   echo shar: Will not over-write existing file \"master_io.c\"
  1527. else
  1528. echo shar: Extracting \"master_io.c\" \(4055 characters\)
  1529. sed "s/^X//" >master_io.c <<'END_OF_master_io.c'
  1530. X#ifndef lint
  1531. Xstatic    char sccsid[] = "@(#)io.c 1.1 86/02/05 SMI"; /* from UCB 1.3 83/07/06 */
  1532. X#endif
  1533. X
  1534. X/* this file contains the I/O handling and the exchange of 
  1535. X   edit characters. This connection itself is established in
  1536. X   ctl.c
  1537. X */
  1538. X
  1539. X#include "talk.h"
  1540. X#include <stdio.h>
  1541. X#include <errno.h>
  1542. X#include <sys/time.h>
  1543. X
  1544. X#define A_LONG_TIME 10000000
  1545. X#define STDIN_MASK (1<<fileno(stdin))    /* the bit mask for standard
  1546. X                       input */
  1547. Xextern int errno;
  1548. Xextern int INPORT, OUTPORT, OUTEND;
  1549. X
  1550. X/*
  1551. X * The routine to do the actual talking
  1552. X */
  1553. X
  1554. Xtalk()
  1555. X{
  1556. X    register int read_template, sockt_mask, inportmask;
  1557. X    BMSG    buf;
  1558. X    char string[10],ch;
  1559. X    int read_set, nb,flag,nbuf=sizeof buf;
  1560. X    struct timeval wait;
  1561. X
  1562. X    current_line = 0;
  1563. X
  1564. X    sockt_mask = (1<<sockt);
  1565. X    inportmask = (1<<INPORT);
  1566. X
  1567. X    /*
  1568. X     * wait on both the other process (sockt_mask) and 
  1569. X     * standard input ( STDIN_MASK )
  1570. X     */
  1571. X
  1572. X    read_template = sockt_mask | inportmask;
  1573. X
  1574. X    forever {
  1575. X
  1576. X    read_set = read_template;
  1577. X
  1578. X    wait.tv_sec = 100000;
  1579. X    wait.tv_usec = 0;
  1580. X
  1581. X    select(32, &read_set, 0, 0, &wait);
  1582. X
  1583. X    if ( read_set & sockt_mask ) { 
  1584. X
  1585. X        /* There is data on sockt */
  1586. X        nb=read(sockt,&buf,nbuf);
  1587. X        if(nb==nbuf)write(OUTPORT, &buf, nbuf);
  1588. X    }
  1589. X    
  1590. X    if ( read_set & inportmask ) {
  1591. X
  1592. X        /* we can't make the tty non_blocking, because
  1593. X           curses's output routines would screw up */
  1594. X        nb=read(INPORT,&buf,nbuf);
  1595. X        if(nb==nbuf)write(sockt, &buf, nbuf);
  1596. X    }
  1597. X    }
  1598. X}
  1599. X
  1600. Xextern int    errno;
  1601. Xextern int    sys_nerr;
  1602. Xextern char    *sys_errlist[];
  1603. X
  1604. X    /* p_error prints the system error message on the standard location
  1605. X       on the screen and then exits. (i.e. a curses version of perror)
  1606. X     */
  1607. X
  1608. Xp_error(string) 
  1609. Xchar *string;
  1610. X{
  1611. X    char *sys;
  1612. X
  1613. X    sys = "Unknown error";
  1614. X    if(errno < sys_nerr) {
  1615. X    sys = sys_errlist[errno];
  1616. X    }
  1617. X
  1618. X
  1619. X    printf("[%s : %s (%d)]\n", string, sys, errno);
  1620. X    quit();
  1621. X}
  1622. X
  1623. X    /* display string in the standard location */
  1624. X
  1625. Xmessage(string)
  1626. Xchar *string;
  1627. X{
  1628. X}
  1629. Xtalk1()
  1630. X{    char    ch,ins[2][40];
  1631. X    static char *im[2]={"Conversation","Input       "};
  1632. X    int    rtn, i, ityp,iwn,wn, row, col, readmask,read_template;
  1633. X    int    inport_mask,read_set;
  1634. X    BMSG    buf;
  1635. X    int    ki[2],nb,nbuf=sizeof buf;
  1636. X    struct    timeval wait;
  1637. X
  1638. X    ityp=1;iwn=12;ki[0]=ki[1]=0;
  1639. X    wmove(comwin[18].x_win,0,0);
  1640. X    wprintw(comwin[18].x_win,"%s",im[ityp]);
  1641. X    wrefresh(comwin[18].x_win);
  1642. X    inport_mask=(1<<INPORT);
  1643. X    read_template=inport_mask | STDIN_MASK;
  1644. X    forever {
  1645. X        read_set=read_template;
  1646. X        wait.tv_sec=100000;
  1647. X        wait.tv_usec=0;
  1648. X        select(32,&read_set,0,0,&wait);
  1649. X        if(read_set&inport_mask){
  1650. X            nb=read(INPORT,&buf,nbuf);
  1651. X            if(nb==nbuf){
  1652. X            wn=WN;row=ROW;col=COL;
  1653. X            if(row<80) wmove(comwin[wn].x_win,row,col);
  1654. X                        if(wn<14&&STR[0]=='\\'){
  1655. X                             TYPE=64;write(OUTPORT,&buf,nbuf);
  1656. X                             endwin();exit();}
  1657. X            if(STR[0]=='Z'|wn==12) wclear(comwin[wn].x_win);
  1658. X                        if(STR[0]!='Z') wprintw(comwin[wn].x_win,"%s",STR);
  1659. X            wrefresh(comwin[wn].x_win);
  1660. X            }
  1661. X        }
  1662. X        if(read_set&STDIN_MASK){
  1663. X            read(0,&ch,1);
  1664. X                        if(ityp==1&&ch=='\\') {
  1665. X                             TYPE=64;write(OUTPORT,&buf,nbuf);
  1666. X                             write(OUTEND,&ch,1);endwin();exit();}
  1667. X            if(ityp==1&&ch<='z'&&ch>='a') ch&=223;
  1668. X            switch(ch){
  1669. X                 case 27:   ityp=1-ityp;iwn=28-iwn;
  1670. X                    wmove(comwin[18].x_win,0,0);
  1671. X                    wprintw(comwin[18].x_win,"%s",im[ityp]);
  1672. X                    wrefresh(comwin[18].x_win);
  1673. X                    break;
  1674. X                 case '\b': if(ki[ityp]>0){
  1675. X                        ki[ityp]--;
  1676. X                        waddch(comwin[iwn].x_win,ch);
  1677. X                        wrefresh(comwin[iwn].x_win);
  1678. X                    }
  1679. X                    break;
  1680. X                 default:   ins[ityp][ki[ityp]++]=ch;
  1681. X                    waddch(comwin[iwn].x_win,ch);
  1682. X                    wrefresh(comwin[iwn].x_win);
  1683. X                    
  1684. X            }
  1685. X            if(ki[ityp]>=comwin[iwn].x_ncols-1&&ch!='\n'){
  1686. X                ch='\n';ins[ityp][ki[ityp]++]=ch;
  1687. X                waddch(comwin[iwn].x_win,ch);
  1688. X                wrefresh(comwin[iwn].x_win);
  1689. X            }
  1690. X            if(ch=='\n'){
  1691. X                if(ityp){wclear(comwin[iwn].x_win);
  1692. X                     wrefresh(comwin[iwn].x_win);}
  1693. X                TYPE=ityp;ins[ityp][ki[ityp]]='\0';
  1694. X                ROW=81;ki[ityp]=0;
  1695. X                strcpy(STR,ins[ityp]);
  1696. X                write(OUTPORT,&buf,nbuf);
  1697. X            }
  1698. X        }
  1699. X    }
  1700. X}
  1701. X
  1702. END_OF_master_io.c
  1703. if test 4055 -ne `wc -c <master_io.c`; then
  1704.     echo shar: \"master_io.c\" unpacked with wrong size!
  1705. fi
  1706. # end of overwriting check
  1707. fi
  1708. if test -f master_talk.c -a "${1}" != "-c" ; then 
  1709.   echo shar: Will not over-write existing file \"master_talk.c\"
  1710. else
  1711. echo shar: Extracting \"master_talk.c\" \(4015 characters\)
  1712. sed "s/^X//" >master_talk.c <<'END_OF_master_talk.c'
  1713. X#include    <errno.h>
  1714. X#include    <signal.h>
  1715. X#include    <stdio.h>
  1716. X#include    "talk.h"
  1717. X#include    <sys/time.h>
  1718. X
  1719. Xextern    int    errno;
  1720. Xxwin_t comwin[19];
  1721. Xint    inport[5], outport[5], pid[5];
  1722. Xint    INPORT, OUTPORT, ID;
  1723. Xint     INEND,OUTEND;
  1724. Xchar    player[4][20];
  1725. Xchar    *getlogin(),*cp;
  1726. Xchar *current_state;
  1727. Xlong     seed;
  1728. Xstruct timeval wait;
  1729. Xint    readmask;
  1730. X
  1731. Xmain(argc, argv)
  1732. Xint    argc;
  1733. Xchar    *argv[];
  1734. X{    int    fides1[2], fides2[2],endpipe[2];
  1735. X    int    i,j, rtn, nb ,wp,read_set,read_template;
  1736. X    char    ins[40],ch;
  1737. X    BMSG    buf;
  1738. X    int nbuf=sizeof buf;
  1739. X    struct sgttyb tty;
  1740. X    struct ltchars ltc;
  1741. X    struct timeval wait;
  1742. X    int    inmask[4], sinmask, readmask, readtmp,intyp;
  1743. X    char    inp[40],*cp,tbuf[10];
  1744. X
  1745. X    time(&seed);
  1746. X        pipe(endpipe);
  1747. X    for (i=0; i<=4; i++){
  1748. X        rtn = pipe(fides1);
  1749. X        if (rtn == -1){
  1750. X            printf("Error in pipe1, errno = %d\n", errno);
  1751. X            exit(-1);
  1752. X        };
  1753. X
  1754. X        rtn = pipe(fides2);
  1755. X        if (rtn == -1){
  1756. X            printf("Error in pipe2, errno = %d\n", errno);
  1757. X            exit(-1);
  1758. X        };
  1759. X
  1760. X        for (pid[i]=fork(); pid[i]<0;pid[i]=fork());
  1761. X        if (pid[i] == 0){
  1762. X            ID = i;
  1763. X            INPORT = fides1[0];
  1764. X            OUTPORT = fides2[1];
  1765. X            switch(i){
  1766. X                            case 4: INEND=endpipe[0];
  1767. X                                   bridge();
  1768. X                   exit();
  1769. X                           case 3: OUTEND=endpipe[1];
  1770. X                                   init_disp();
  1771. X                   talk1();
  1772. X                                   exit();
  1773. X                           case 2:
  1774. X                           case 1:
  1775. X                           case 0:
  1776. X                       comm(2, &argv[i]);
  1777. X                       exit();
  1778. X            }
  1779. X        };
  1780. X        inport[i] = fides2[0];
  1781. X        outport[i] = fides1[1];
  1782. X                cp=(char *)player[i];cp+=2;
  1783. X        if(i==3)strncpy(cp, getlogin(), 6);
  1784. X        if (i<3){strncpy(cp, argv[i+1], 6);
  1785. X            do{
  1786. X            rtn = read(inport[i], tbuf, 10);
  1787. X            }while(rtn <= 1);
  1788. X        }
  1789. X    };
  1790. X    read_template=0; wp=0; ins[0]=ins[1]=ins[2]=0;
  1791. X    for(i=0;i<=4;++i){read_template|=(1<<inport[i]);}
  1792. X    forever{
  1793. X        read_set=read_template;
  1794. X        wait.tv_sec=100000;
  1795. X        select(32,&read_set,0,0,&wait);
  1796. X        for(i=0;i<=3;++i){
  1797. X            if(!(read_set&(1<<inport[i]))) continue;
  1798. X            nb=read(inport[i],&buf,nbuf);
  1799. X            if(nb==nbuf){
  1800. X                        if(TYPE==64)exit();
  1801. X            if(TYPE){
  1802. X                if(!(wp&(1<<i))) continue;
  1803. X                wp-=(1<<i);
  1804. X                for(j=0;j<=2;++j) ins[j]|=STR[j];
  1805. X            }
  1806. X            else{
  1807. X                for(j=0;j<=3;++j){
  1808. X                    WN=14+(j-i+6)%4;
  1809. X                    if(i!=j){
  1810. X                      write(outport[j],&buf,sizeof buf);
  1811. X                    }
  1812. X                }
  1813. X            }
  1814. X            }
  1815. X        }
  1816. X        if(read_set&(1<<inport[4])){
  1817. X            nb=read(inport[4],&buf,nbuf);
  1818. X            if(nb==nbuf){
  1819. X            intyp=TYPE;
  1820. X            for(i=0;i<=3;++i){
  1821. X                if(TYPE&(1<<i)) write(outport[i],&buf,nbuf);
  1822. X            }
  1823. X            if(TYPE>15) wp=TYPE&15; else wp=0;
  1824. X                        ins[0]=ins[1]=ins[2]=0;
  1825. X            }
  1826. X        }
  1827. X        if(intyp<32&&intyp>15 && wp ==0){ 
  1828. X            strncpy(STR,ins,3);
  1829. X            write(outport[4],&buf,nbuf);intyp=0;}
  1830. X        if(intyp>31&&((intyp&15)^wp)){ 
  1831. X            write(outport[4],&buf,nbuf);intyp=0;}
  1832. X    }
  1833. X}
  1834. X
  1835. Xcomm(argc, argv)
  1836. Xint argc;
  1837. Xchar *argv[];
  1838. X{    char    string[10];
  1839. X
  1840. X    get_names(argc, argv);
  1841. X
  1842. X
  1843. X    open_ctl();
  1844. X    open_sockt();
  1845. X    start_msgs();
  1846. X
  1847. X    if ( !check_local() ) {
  1848. X        invite_remote();
  1849. X    }
  1850. X
  1851. X    end_msgs();
  1852. X    write(OUTPORT, string, 10);
  1853. X
  1854. X    talk();
  1855. X}
  1856. Xrsend(p, ww, rr, cc, s)
  1857. Xint    p, ww, rr, cc;
  1858. Xchar    *s;
  1859. X{    BMSG    buf;
  1860. X    int    nbuf = sizeof buf, rtn;
  1861. X    char    w, r, c;
  1862. X
  1863. X    w = ww; r = rr; c = cc;
  1864. X        WN = w; ROW = r; COL = c; TYPE = p; strcpy(STR, s);
  1865. X        rtn = write(OUTPORT, &buf, nbuf);
  1866. X        if (rtn <= 0){
  1867. X            printf("lost pipe write %d, %d", p, errno);
  1868. X            exit();
  1869. X        };
  1870. X}
  1871. X
  1872. Xrput(p,w,r,c,s)
  1873. Xint p,w,r,c;
  1874. Xchar *s;
  1875. X{
  1876. X   rsend(1<<p,w,r,c,s);
  1877. X}
  1878. X
  1879. Xrwait(p, s, t)
  1880. Xint    p;
  1881. Xlong    t;
  1882. Xchar    *s;
  1883. X{
  1884. X    char    ch;
  1885. X    int    readset=0,rtn;
  1886. X    struct    timeval    wait;
  1887. X    BMSG    buf;
  1888. X
  1889. X    if(t<100)p+=16;
  1890. X    rsend(p+16,12,0,0,s);
  1891. X    wait.tv_sec=0;
  1892. X    readset=(1<<INPORT);
  1893. X    while(select(32,&readset,0,0,&wait)>0){
  1894. X        wait.tv_sec=0;
  1895. X        read(INPORT,&buf,sizeof buf);
  1896. X        readset=(1<<INPORT);
  1897. X    }
  1898. X    wait.tv_sec=t;
  1899. X    wait.tv_usec=0;
  1900. X    readset=(1<<INPORT)|(1<<INEND);
  1901. X    rtn=select(32,&readset,0,0,&wait);
  1902. X    if (rtn>0){
  1903. X                if(readset&(1<<INEND)) exit();
  1904. X        read(INPORT,&buf,sizeof buf);
  1905. X        strncpy(s,STR,3);
  1906. X    }
  1907. X    return(rtn);
  1908. X}    
  1909. X
  1910. Xrget(p, s)
  1911. Xint    p;
  1912. Xchar    *s;
  1913. X{
  1914. X    rwait(p,s,99999);
  1915. X}
  1916. END_OF_master_talk.c
  1917. if test 4015 -ne `wc -c <master_talk.c`; then
  1918.     echo shar: \"master_talk.c\" unpacked with wrong size!
  1919. fi
  1920. # end of overwriting check
  1921. fi
  1922. if test -f msgs.c -a "${1}" != "-c" ; then 
  1923.   echo shar: Will not over-write existing file \"msgs.c\"
  1924. else
  1925. echo shar: Extracting \"msgs.c\" \(922 characters\)
  1926. sed "s/^X//" >msgs.c <<'END_OF_msgs.c'
  1927. X#ifndef lint
  1928. Xstatic    char sccsid[] = "@(#)msgs.c 1.1 86/02/05 SMI"; /* from UCB 1.4 83/07/06 */
  1929. X#endif
  1930. X
  1931. X/* 
  1932. X * a package to display what is happening every MSG_INTERVAL seconds
  1933. X * if we are slow connecting.
  1934. X */
  1935. X
  1936. X#include <signal.h>
  1937. X#include <stdio.h>
  1938. X#include <sys/time.h>
  1939. X#include "talk.h"
  1940. X
  1941. X#define MSG_INTERVAL 4
  1942. X#define LONG_TIME 100000
  1943. X
  1944. Xchar *current_state;
  1945. Xint current_line = 0;
  1946. X
  1947. Xstatic struct itimerval itimer;
  1948. Xstatic struct timeval wait = { MSG_INTERVAL , 0};
  1949. Xstatic struct timeval undo = { LONG_TIME, 0};
  1950. X    
  1951. X
  1952. Xdisp_msg()
  1953. X{
  1954. X    message(current_state);
  1955. X}
  1956. X
  1957. Xstart_msgs()
  1958. X{
  1959. X    message(current_state);
  1960. X    signal(SIGALRM, disp_msg);
  1961. X    itimer.it_value = itimer.it_interval = wait;
  1962. X    setitimer(ITIMER_REAL, &itimer, (struct timerval *)0);
  1963. X}
  1964. X
  1965. Xend_msgs()
  1966. X{
  1967. X    signal(SIGALRM, SIG_IGN);
  1968. X    timerclear(&itimer.it_value);
  1969. X    timerclear(&itimer.it_interval);
  1970. X    setitimer(ITIMER_REAL, &itimer, (struct timerval *)0);
  1971. X}
  1972. END_OF_msgs.c
  1973. if test 922 -ne `wc -c <msgs.c`; then
  1974.     echo shar: \"msgs.c\" unpacked with wrong size!
  1975. fi
  1976. # end of overwriting check
  1977. fi
  1978. if test -f slave_io.c -a "${1}" != "-c" ; then 
  1979.   echo shar: Will not over-write existing file \"slave_io.c\"
  1980. else
  1981. echo shar: Extracting \"slave_io.c\" \(2340 characters\)
  1982. sed "s/^X//" >slave_io.c <<'END_OF_slave_io.c'
  1983. X#include "talk.h"
  1984. X#include <stdio.h>
  1985. X#include <errno.h>
  1986. X#include <sys/time.h>
  1987. X
  1988. X#define A_LONG_TIME 10000000
  1989. X#define STDIN_MASK (1<<fileno(stdin))    /* the bit mask for standard
  1990. X                       input */
  1991. Xextern int errno;
  1992. X
  1993. X/*
  1994. X * The routine to do the actual talking
  1995. X */
  1996. X
  1997. X
  1998. Xtalk()
  1999. X{    char    ch,ins[2][40];
  2000. X    static char *im[2]={"Conversation","Input       "};
  2001. X    int    rtn, i, ityp,iwn,wn, row, col, readmask,read_template;
  2002. X    int    sockt_mask,read_set;
  2003. X    BMSG    buf;
  2004. X    int    ki[2],nb,nbuf=sizeof buf;
  2005. X    struct    timeval wait;
  2006. X
  2007. X    ityp=1;iwn=12;ki[0]=ki[1]=0;
  2008. X    wmove(comwin[18].x_win,0,0);
  2009. X    wprintw(comwin[18].x_win,"%s",im[ityp]);
  2010. X    wrefresh(comwin[18].x_win);
  2011. X    sockt_mask=(1<<sockt);
  2012. X    read_template=sockt_mask | STDIN_MASK;
  2013. X    forever {
  2014. X        read_set=read_template;
  2015. X        wait.tv_sec=100000;
  2016. X        wait.tv_usec=0;
  2017. X        select(32,&read_set,0,0,&wait);
  2018. X        if(read_set&sockt_mask){
  2019. X            nb=read(sockt,&buf,nbuf);
  2020. X            if(nb==nbuf){
  2021. X            wn=WN;row=ROW;col=COL;
  2022. X            if(row<80) wmove(comwin[wn].x_win,row,col);
  2023. X                        if(wn<14&&STR[0]=='\\'){endwin();exit();}
  2024. X            if(STR[0]=='Z'|wn==12) wclear(comwin[wn].x_win);
  2025. X                        if(STR[0]!='Z') wprintw(comwin[wn].x_win,"%s",STR);
  2026. X            wrefresh(comwin[wn].x_win);
  2027. X            }
  2028. X        }
  2029. X        if(read_set&STDIN_MASK){
  2030. X            read(0,&ch,1);
  2031. X            if(ityp==1&&ch<='z'&&ch>='a') ch&=223;
  2032. X            switch(ch){
  2033. X                 case 27:   ityp=1-ityp;iwn=28-iwn;
  2034. X                    wmove(comwin[18].x_win,0,0);
  2035. X                    wprintw(comwin[18].x_win,"%s",im[ityp]);
  2036. X                    wrefresh(comwin[18].x_win);
  2037. X                    break;
  2038. X                 case '\b': if(ki[ityp]>0){
  2039. X                        ki[ityp]--;
  2040. X                        waddch(comwin[iwn].x_win,ch);
  2041. X                        wrefresh(comwin[iwn].x_win);
  2042. X                    }
  2043. X                    break;
  2044. X                 default:   ins[ityp][ki[ityp]++]=ch;
  2045. X                    waddch(comwin[iwn].x_win,ch);
  2046. X                    wrefresh(comwin[iwn].x_win);
  2047. X                    
  2048. X            }
  2049. X            if(ki[ityp]>=comwin[iwn].x_ncols-1&&ch!='\n'){
  2050. X                ch='\n';ins[ityp][ki[ityp]++]=ch;
  2051. X                waddch(comwin[iwn].x_win,ch);
  2052. X                wrefresh(comwin[iwn].x_win);
  2053. X            }
  2054. X            if(ch=='\n'){
  2055. X                if(ityp){wclear(comwin[iwn].x_win);
  2056. X                     wrefresh(comwin[iwn].x_win);}
  2057. X                TYPE=ityp;ins[ityp][ki[ityp]]='\0';
  2058. X                ROW=81;ki[ityp]=0;
  2059. X                strcpy(STR,ins[ityp]);
  2060. X                write(sockt,&buf,nbuf);
  2061. X            }
  2062. X        }
  2063. X    }
  2064. X}
  2065. X
  2066. X
  2067. Xp_error(string) 
  2068. Xchar *string;
  2069. X{
  2070. X    char *sys;
  2071. X
  2072. X    sys = "Unknown error";
  2073. X
  2074. X
  2075. X    printf("[%s : %s (%d)]\n", string, sys, errno);
  2076. X    quit();
  2077. X}
  2078. X
  2079. X    /* display string in the standard location */
  2080. X
  2081. Xmessage(string)
  2082. Xchar *string;
  2083. X{
  2084. X}
  2085. END_OF_slave_io.c
  2086. if test 2340 -ne `wc -c <slave_io.c`; then
  2087.     echo shar: \"slave_io.c\" unpacked with wrong size!
  2088. fi
  2089. # end of overwriting check
  2090. fi
  2091. echo shar: End of archive 1 \(of 2\).
  2092. cp /dev/null ark1isdone
  2093. MISSING=""
  2094. for I in 1 2 ; do
  2095.     if test ! -f ark${I}isdone ; then
  2096.     MISSING="${MISSING} ${I}"
  2097.     fi
  2098. done
  2099. if test "${MISSING}" = "" ; then
  2100.     echo You have unpacked both archives.
  2101.     rm -f ark[1-9]isdone
  2102. else
  2103.     echo You still need to unpack the following archives:
  2104.     echo "        " ${MISSING}
  2105. fi
  2106. ##  End of shell archive.
  2107. exit 0
  2108.